﻿namespace FrameWork.Lib.HTML
{
    using System;
    using System.ComponentModel;

    public class HtmlAttribute
    {
        protected string mName;
        protected string mValue;

        public HtmlAttribute()
        {
            this.mName = "Unnamed";
            this.mValue = "";
        }

        public HtmlAttribute(string name, string value)
        {
            this.mName = name;
            this.mValue = value;
        }

        public override string ToString()
        {
            if (this.mValue == null)
            {
                return this.mName;
            }
            return (this.mName + "=\"" + this.mValue + "\"");
        }

        [Category("Output"), Description("The HTML to represent this attribute")]
        public string HTML
        {
            get
            {
                if (this.mValue == null)
                {
                    return this.mName;
                }
                return (this.mName + "=\"" + HtmlEncoder.EncodeValue(this.mValue) + "\"");
            }
        }

        [Category("General"), Description("The name of the attribute")]
        public string Name
        {
            get
            {
                return this.mName;
            }
            set
            {
                this.mName = value;
            }
        }

        [Category("General"), Description("The value of the attribute")]
        public string Value
        {
            get
            {
                return this.mValue;
            }
            set
            {
                this.mValue = value;
            }
        }

        [Description("The XHTML to represent this attribute"), Category("Output")]
        public string XHTML
        {
            get
            {
                if (this.mValue == null)
                {
                    return this.mName.ToLower();
                }
                return (this.mName + "=\"" + HtmlEncoder.EncodeValue(this.mValue.ToLower()) + "\"");
            }
        }
    }
}

